<template>
  <div class="page">
    <form>
      <slot></slot>
    </form>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  provide() {
    return {
      mForm: this
    };
  },
  props: {
    model: {
      type: Object,
      default: {}
    },
    rules: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      files: []
    };
  },

  //写在mounted中formItemAdd调不到
  created() {
    this.$on("formItemAdd", item => {
      this.files.push(item);
    });
  },
  methods: {
    async validate(callback) {
      let tasks = this.files.map(item => item.validator());
      const results = await Promise.all(tasks);
      let ret = true;
      results.forEach(valid => {
        if (!valid) {
          ret = false;
        }
      });
      callback(ret);
    }
  },
  components: {}
};
</script>

<style scoped>
</style>
